﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ProjectThuCung.Models;

namespace ProjectThuCung.Controllers
{
    public class HomeController : Controller
    {
        ThuCungDB db = new ThuCungDB();
        public ActionResult Index(string Timkiem, string Gia, string Xuat_xu)
        {
            if (Timkiem != null)
                return RedirectToAction("TimSanPham", "SanPham", new { timkiem = Timkiem, gia = Gia, xuatxu = Xuat_xu });
            ViewBag.thucung = (from p in db.SanPhams
                            orderby p.SanPhamID descending
                            where p.LoaiSanPham.SubLoaiSanPham == SubLoaiSP.ThuCung
                            select p).Skip(0).Take(4).ToList();

            ViewBag.thucan = (from p in db.SanPhams
                        orderby p.SanPhamID descending
                        where p.LoaiSanPham.SubLoaiSanPham == SubLoaiSP.ThucAn
                        select p).Skip(0).Take(4).ToList();


            ViewBag.thuoc = (from p in db.SanPhams
                        orderby p.SanPhamID descending
                        where p.LoaiSanPham.SubLoaiSanPham == SubLoaiSP.Thuoc
                        select p).Skip(0).Take(4).ToList();


            ViewBag.dochoi = (from p in db.SanPhams
                        orderby p.SanPhamID descending
                        where p.LoaiSanPham.SubLoaiSanPham == SubLoaiSP.DoChoi
                        select p).Skip(0).Take(4).ToList();


            ViewBag.chuong = (from p in db.SanPhams
                        orderby p.SanPhamID descending
                        where p.LoaiSanPham.SubLoaiSanPham == SubLoaiSP.Chuong
                        select p).Skip(0).Take(4).ToList();

            return View();
        }

        public ActionResult About(string Timkiem, string Gia, string Xuat_xu)
        {
            if (Timkiem != null)
                return RedirectToAction("TimSanPham", "SanPham", new { timkiem = Timkiem, gia = Gia, xuatxu = Xuat_xu });
            return View();
        }

        public ActionResult Contact(string Timkiem, string Gia, string Xuat_xu)
        {
            if (Timkiem != null)
                return RedirectToAction("TimSanPham", "SanPham", new { timkiem = Timkiem, gia = Gia, xuatxu = Xuat_xu });
            return View();
        }
    }
}
